package com.xiaochong.bitong.api.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.bitong.api.component.RedisCacheComponent;
import com.xiaochong.bitong.api.config.hbase.HbaseBaseQueryComponent;
import com.xiaochong.bitong.api.constant.ReturnCode;
import com.xiaochong.bitong.api.utils.ListSortUtil;
import com.xiaochong.bitong.api.utils.TimeSeconds;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.common.data.hbasepo.OrderBook;
import com.xiaochong.tir.common.data.hbasepo.OrderBookData;
import com.xiaochong.tir.common.data.hbasepo.TradesHistory;
import com.xiaochong.tir.common.data.hbasepo.TradesToKLine;
import com.xiaochong.tir.common.data.mapper.*;
import com.xiaochong.tir.common.data.po.*;
import com.xiaochong.tir.common.data.redisPo.CoinPriceVo;
import com.xiaochong.tir.common.data.vo.*;
import com.xiaochong.tir.common.data.vo.app.AppFundsFlowVo;
import com.xiaochong.tir.common.data.vo.app.AppOrderBookVo;
import com.xiaochong.tir.common.data.vo.app.AppSelfSelectCoinPairVo;
import com.xiaochong.tir.common.data.vo.app.WsExchangePairVo;
import com.xiaochong.tir.common.exception.hbase.HbaseCloseExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseConnectionExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseGetTableExcetion;
import com.xiaochong.tir.common.util.*;
import net.sf.json.util.JSONTokener;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: k线详情
 * @Author: org
 * @CreateDate: 2018/8/10 12:32
 */
@Service
public class KActionDetailService {

    @Autowired
    private RedisServer redisServer;

    @Autowired
    private HbaseBaseQueryComponent hbaseBaseQueryComponent;

    @Autowired
    private ExchangeInfoMapper exchangeInfoMapper;

    @Autowired
    private ExchangeDimensionMiddleMapper exchangeDimensionMiddleMapper;

    @Autowired
    private ExchangeTransactionpairMiddleMapper exchangeTransactionpairMiddleMapper;
    @Autowired
    private PurchaseOrderMapper purchaseOrderMapper;

    @Autowired
    private KLineMapper kLineMapper;
    @Autowired
    private CommonService commonService;
    @Autowired
    private SelfSelectedMapper selfSelectedMapper;
    @Autowired
    private FundsFlowMapper fundsFlowMapper;
    @Autowired
    private RedisCacheComponent redisCacheComponent;
    @Autowired
    private CurrencyInfoMapper currencyInfoMapper;

    public ApiResultVo kActionLongTime(String longTime, String exchangeId, String transactionName, Integer num) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == num || null == exchangeId || StringUtils.isBlank(transactionName) || StringUtils.isBlank(longTime)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("k线数据-K线图按照最后时间戳和条数查询","longTime",longTime,"exchangeId",exchangeId,"transactionName",transactionName,"num",String.valueOf(num));
            Long nowTImeres = Long.valueOf(longTime);
            List<TradesToKLine> resultList=new ArrayList<>();
            String grailStr="";
            TradesToKLine tradesToKLine;
            LocalDateTime timeres = DateUtils.getDateTimeOfTimestamp(nowTImeres);
            for(int i=1;i<=num.intValue();i++){
                timeres = timeres.minusMinutes(i);
                String lastRowKey = DateUtils.localDateTimeFormatString(timeres,DateUtils.format_ymdhm);//当前时间转成分钟
                String rowKey = exchangeId+"@"+transactionName+"@"+lastRowKey;
                grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.API_SERVICE_K_ACTION_TABLE_NAME
                        , HbaseTableUtils.API_SERVICE_K_ACTION_TABLE_NAME_FAMILY
                        , HbaseTableUtils.API_SERVICE_K_ACTION_QUALIFIER
                        , rowKey
                );
                if (grailStr!=null){
                    Object listArray = new JSONTokener(grailStr).nextValue();
                    tradesToKLine = new TradesToKLine();
                    if(listArray instanceof  net.sf.json.JSONArray){//老数据兼容问题
                        JSONArray jsonArray = JSON.parseArray(grailStr);
                        tradesToKLine.setTimestamp(jsonArray.getString(0));
                        tradesToKLine.setOpenPrice(jsonArray.getString(1));
                        tradesToKLine.setHighestPrice(jsonArray.getString(2));
                        tradesToKLine.setLowestPrice(jsonArray.getString(3));
                        tradesToKLine.setClosePrice(jsonArray.getString(4));
                        tradesToKLine.setVolume(jsonArray.getString(5));
                    }else{
                        tradesToKLine = JSON.parseObject(grailStr,TradesToKLine.class);
                    }
                    resultList.add(tradesToKLine);
                }
            }
            //判断数据是否存在
            if(resultList.size() > 0){
                Collections.reverse( resultList );
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查到数据");
            }
            resultVo.setData( resultList );
            resultVo.setPages( resultList.size() );
        }catch (Exception e){
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统异常");
            LogTrace.error("k线数据-K线图按照最后时间戳和条数查询Error",e);
            e.printStackTrace();
        }
        return resultVo;
    }

    public ApiResultVo kActionOfTwoDay( String exchangeId, String transactionName) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("k线数据-K线图-两天数据","exchangeId",exchangeId,"transactionName",transactionName);
            List<TradesToKLine> resultList=new ArrayList<>();
            String grailStr=null;
            TradesToKLine tradesToKLine;
            //Long nowTImeres = DateUtils.getLongTIme( kDate )+86400000;
//            LocalDateTime timeres = DateUtils.getDateTimeOfTimestamp( nowTImeres);
            LocalDateTime timeres = LocalDateTime.now().plusMinutes(1);
            int size = 1;
            for(int i=0;i<600;i++){
                if(size > 300){
                    break;
                }
                timeres = timeres.minusMinutes(1);
                String lastRowKey = DateUtils.localDateTimeFormatString(timeres,DateUtils.format_ymdhm);//当前时间转成分钟
                String rowKey = exchangeId+"@"+transactionName+"@"+lastRowKey;
                grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.API_SERVICE_K_ACTION_TABLE_NAME
                        , HbaseTableUtils.API_SERVICE_K_ACTION_TABLE_NAME_FAMILY
                        , HbaseTableUtils.API_SERVICE_K_ACTION_QUALIFIER
                        , rowKey
                );
                if (grailStr!=null){
                    Object listArray = new JSONTokener(grailStr).nextValue();
                    tradesToKLine = new TradesToKLine();
                    if(listArray instanceof  net.sf.json.JSONArray){//老数据兼容问题
                        JSONArray jsonArray = JSON.parseArray(grailStr);
                        tradesToKLine.setTimestamp(jsonArray.getString(0));
                        tradesToKLine.setOpenPrice(jsonArray.getString(1));
                        tradesToKLine.setHighestPrice(jsonArray.getString(2));
                        tradesToKLine.setLowestPrice(jsonArray.getString(3));
                        tradesToKLine.setClosePrice(jsonArray.getString(4));
                        tradesToKLine.setVolume(jsonArray.getString(5));
                    }else{
                        tradesToKLine = JSON.parseObject(grailStr,TradesToKLine.class);
                    }
                    resultList.add(tradesToKLine);
                    size++;
                }
            }
            //判断数据是否存在
            if(resultList.size() > 0){
                Collections.reverse( resultList );
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
            }
            resultVo.setData( resultList );
            resultVo.setPages( resultList.size() );
        }catch (Exception e){
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统异常");
            LogTrace.error("k线数据-K线图-两天数据Error",e);
            e.printStackTrace();
        }
        return resultVo;
    }

    public ApiResultVo NewkAction(String exchangeId, String transactionName) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("k线数据-K线图-最新数据","exchangeId",exchangeId,"transactionName",transactionName);
            List<TradesToKLine> kLineList = makekActionNewData(exchangeId,transactionName);
            if(kLineList != null && kLineList.size() > 0){
                resultVo.setCode( ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
                resultVo.setData(kLineList);
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
            }
        }catch (Exception e){
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统异常");
            LogTrace.error("k线数据-K线图-最新数据error",e);
            e.printStackTrace();
        }
        return resultVo;
    }
    public List<TradesToKLine> makekActionNewData(String exchangeId, String transactionName) {
        String klineRedis = RedisKeysUtils.API_SERVICE_K_ACTION_TRADES_TWO + "@" + exchangeId + "@" + transactionName;
        String grailStr = redisServer.get(klineRedis);
        if (StringUtils.isNotBlank(grailStr)) {
            List<TradesToKLine> kLineList = JSON.parseArray(grailStr, TradesToKLine.class);
            return kLineList;
        }
        return null;
    }
    /**
     * 获取交易所列表
     * @return
     */
    public ApiResultVo getTransactions() {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            ExchangeInfo exchangeInfo=new ExchangeInfo();
            exchangeInfo.setEnableFlag( true );
            exchangeInfo.setDeleteFlag( false );
            exchangeInfo.setKlineStatus( true );
            List<ExchangeInfo> infoList=exchangeInfoMapper.selectByEntityList( exchangeInfo );
            List<ExchangeInfo> infoList2=new ArrayList<>(  );
            List<ExchangeInfo> infoList3=new ArrayList<>(  );
            List<ExchangeInfo> infoList4=new ArrayList<>(  );

            for (int i=0;i<infoList.size();i++){
                ExchangeInfo info = infoList.get( i );
                if(infoList.get( i ).getSort()!=null){
                    infoList2.add( info );
                }else{
                    infoList3.add( info );
                }
            }
            ListSortUtil sortUtil=new ListSortUtil();
            sortUtil.mySort( infoList2,"sort","asc" );
            for(int i=0;i<infoList3.size();i++){
                ExchangeInfo info=new ExchangeInfo();
                info.setExchangeName( infoList3.get( i ).getExchangeName() );
                info.setId( infoList3.get( i ).getId() );
                infoList4.add( info );
                infoList3.get( i ).setExchangeName( infoList3.get( i ).getExchangeName().toUpperCase() );
            }
            sortUtil.mySort( infoList3,"exchangeName","asc" );
            for(int i=0;i<infoList3.size();i++){
                for (int j=0;j<infoList4.size();j++){
                    if(infoList4.get( j ).getId() .equals(   infoList3.get( i ).getId()) ){
                        infoList3.get( i ).setExchangeName( infoList4.get( j ).getExchangeName() );
                    }
                }
            }
            infoList2.addAll( infoList3 );
            resultVo.setCode( ReturnCode.SUCCESS);
            resultVo.setMessage("成功");
            resultVo.setData( infoList2 );
            resultVo.setTotal( infoList2.size() );
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取交易所列表error", e);
        }
        return resultVo;
    }

    /**
     * 获取交易所时间维度-k线图
     * @return
     */
    public ApiResultVo getDimensions(Integer exchangeId) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            ExchangeDimensionMiddle exchangeDimensionMiddle=new ExchangeDimensionMiddle();
            exchangeDimensionMiddle.setEnableFlag( true );
            exchangeDimensionMiddle.setExchangeId(exchangeId);
            List<ExchangeDimensionMiddle> middleList=exchangeDimensionMiddleMapper.selectByEntityList( exchangeDimensionMiddle );
            for (int i=0;i<middleList.size();i++){
                ExchangeDimensionMiddle middle=middleList.get( i );
                int time=0;
                try {
                    time= TimeSeconds.getValue(middle.getDimensionName());
                }catch (Exception e){
                    e.printStackTrace();
                    LogTrace.error("获取交易所时间维度-k线图error1",e);
                }
                middle.setSeconds(time);
            }
            ListSortUtil sortUtil=new ListSortUtil();
            sortUtil.mySort( middleList,"seconds","asc" );
            resultVo.setCode( ReturnCode.SUCCESS);
            resultVo.setMessage("成功");
            resultVo.setData( middleList );
            resultVo.setTotal( middleList.size() );
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取交易所时间维度-k线图error", e);
        }
        return resultVo;
    }

    /**
     * 获取最新历史交易数据
     * @param exchangeId
     * @param transactionName
     * @return
     */
    public ApiResultVo getTranes(Integer exchangeId, String transactionName) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("获取最新历史交易数据","exchangeId",String.valueOf(exchangeId),"transactionName",transactionName);
            /*ExchangeTransactionpairMiddle query = new ExchangeTransactionpairMiddle();
            query.setTransactionId(transactionId);
            query.setExchangeId( exchangeId );
            ExchangeTransactionpairMiddle exchangeTransactionpairMiddle = exchangeTransactionpairMiddleMapper.selectByEntity(query);
            if(exchangeTransactionpairMiddle == null || !exchangeTransactionpairMiddle.getEnableFlag()){
                LogTrace.info("tranes","exchangeTransactionpairMiddle",transactionId+"查询不可用");
                resultVo.setCode( ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                return resultVo;
            }*/
            //redis
            List<ApiTradesHistoryVo> tradesHistoryVos = getTreasMakeDate(exchangeId,transactionName);
            if (tradesHistoryVos != null && tradesHistoryVos.size() > 0) {
                resultVo.setData( tradesHistoryVos );
                resultVo.setCode( ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
                resultVo.setTotal( tradesHistoryVos.size() );
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
                resultVo.setTotal(0 );
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取最新历史交易数据error", e);
        }
        return resultVo;
    }
    public List<ApiTradesHistoryVo> getTreasMakeDate(Integer exchangeId, String transactionName){
        String Rediskey = RedisKeysUtils.API_SERVICE_TRADES + "@" + exchangeId + "@" + transactionName;
        String API_SERVICE_TRADES = redisServer.get( Rediskey );
        List<ApiTradesHistoryVo> tradesHistoryVos = new ArrayList<>();
        if (API_SERVICE_TRADES != null) {
            ApiTradesHistoryVo apiTradesHistoryVo;
            List<TradesHistory> tradesHistoryList = JSON.parseArray(API_SERVICE_TRADES, TradesHistory.class);
            if (tradesHistoryList != null && tradesHistoryList.size() > 0) {
                for (TradesHistory tradesHistory : tradesHistoryList) {
                    apiTradesHistoryVo = new ApiTradesHistoryVo();
                    apiTradesHistoryVo.setAmount(tradesHistory.getAmount().stripTrailingZeros().toPlainString());
                    apiTradesHistoryVo.setPrice(tradesHistory.getPrice().stripTrailingZeros().toPlainString());
                    apiTradesHistoryVo.setTimestamp(tradesHistory.getTimestamp());
                    apiTradesHistoryVo.setBuyOrSellFlag(tradesHistory.getSide());
                    tradesHistoryVos.add(apiTradesHistoryVo);
                }
            }
        }
        return  tradesHistoryVos;
    }
    public ApiResultVo<ApiTradesHistoryVo> getTranesList(Integer exchangeId, String transactionName) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("获取最新历史交易数据","exchangeId",String.valueOf(exchangeId),"transactionName",transactionName);
            String Rediskey = RedisKeysUtils.API_SERVICE_TRADES_ALL_DATA+"@"+exchangeId+"@"+transactionName;
            String API_SERVICE_TRADES_ALL_DATA=redisServer.get(Rediskey);
            if(org.apache.commons.lang3.StringUtils.isNotBlank(API_SERVICE_TRADES_ALL_DATA)){
                List<ApiTradesHistoryVo> tradesHistoryVos = new ArrayList<>();
                ApiTradesHistoryVo apiTradesHistoryVo;
                List<TradesHistory> tradesHistoryList = JSON.parseArray(API_SERVICE_TRADES_ALL_DATA,TradesHistory.class);
                if(tradesHistoryList!=null && tradesHistoryList.size()>0){
                    for(TradesHistory tradesHistory :tradesHistoryList){
                        apiTradesHistoryVo = new ApiTradesHistoryVo();
                        apiTradesHistoryVo.setAmount(tradesHistory.getAmount().stripTrailingZeros().toPlainString());
                        apiTradesHistoryVo.setPrice(tradesHistory.getPrice().stripTrailingZeros().toPlainString());
                        apiTradesHistoryVo.setTimestamp(tradesHistory.getTimestamp());
                        apiTradesHistoryVo.setBuyOrSellFlag(tradesHistory.getSide());
                        tradesHistoryVos.add(apiTradesHistoryVo);
                    }
                }
                resultVo.setData( tradesHistoryVos );
                resultVo.setCode( ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
                resultVo.setTotal( tradesHistoryVos.size() );
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
                resultVo.setTotal(0 );
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取最新历史交易数据error", e);
        }
        return resultVo;
    }

    /**
     * 表头数据
     * @param exchangeId
     * @param transactionName
     * @return
     */
    public ApiResultVo getRise(Integer exchangeId, String transactionName) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("获取K线表头数据","exchangeId",String.valueOf(exchangeId),"transactionName",transactionName);
            JSONObject jsonObject = makeRiseData(exchangeId,transactionName);
            if (jsonObject != null) {
                resultVo.setData( jsonObject );
                resultVo.setCode( ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取K线表头数据error", e);
        }
        return resultVo;
    }
    public JSONObject makeRiseData(Integer exchangeId,String transactionName) throws HbaseCloseExcetion, HbaseGetTableExcetion, HbaseConnectionExcetion, IOException {
        String redisPriceDate = DateUtils.localDateTimeFormatString(LocalDateTime.now(),DateUtils.format_ymds);
        String Rediskey = RedisKeysUtils.API_SERVICE_K_ACTION_ALL_DATA_PRICE + "@" + exchangeId + "@" + transactionName;
        String API_SERVICE_K_ACTION_CHANGE_PRICE = redisServer.get( Rediskey );
        if (API_SERVICE_K_ACTION_CHANGE_PRICE != null) {
            ApiWebSocketVo vo = new ApiWebSocketVo();
            JSONObject jsonObject = JSON.parseObject(API_SERVICE_K_ACTION_CHANGE_PRICE);
            //设置保留小数位数
            jsonObject.put("newPriceUsd",getConverCut(jsonObject.getBigDecimal("newPriceUsd")));
            jsonObject.put("lastOpenPrice",getConverCut(new BigDecimal(String.valueOf(jsonObject.get("lastOpenPrice")))));
            jsonObject.put("maxPrice",getConverCut(new BigDecimal(String.valueOf(jsonObject.get("maxPrice")))));
            jsonObject.put("minPrice",getConverCut(new BigDecimal(String.valueOf(jsonObject.get("minPrice")))));
            jsonObject.put("allAmount", CountCoinAmount(exchangeId, transactionName));
            return  jsonObject;
        }
        return  null;
    }
    /**
     * 获取日k-k线数据
     * @param exchangeId
     * @param transactionName
     * @return
     */
    public ApiResultVo<KLine> getDayLine(Integer exchangeId, String transactionName) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("获取日k-k线数据","exchangeId",String.valueOf(exchangeId),"transactionName",transactionName);
            // 日K数据加入redis
            String key = "daykline_"+exchangeId+"_"+transactionName;
            //缓存过期时间
            long expireTime = 60*60*3;
            List<KLine> kList;
            String data ;
            data = redisServer.get(key);
            if(data!=null){
                LogTrace.infoKvs("daykline命中缓存" ,"exchangeId" , exchangeId+"","transactionName" , transactionName );
                kList = JSON.parseArray(data , KLine.class);
            }else{
                LogTrace.infoKvs("daykline查询" ,"exchangeId" , exchangeId+"","transactionName" , transactionName );

                KLine kLine=new KLine();
                kLine.setExchangeId( exchangeId );
                kLine.setTransationPairName(  transactionName);
                kList = kLineMapper.selectKline12h( kLine );
                //日期转时间戳
                for (int i=0;i<kList.size();i++){
                    kList.get( i ).setKDate( DateUtils.getLongTIme2(kList.get( i ).getKDate()).toString() );
                }
                if(kList.size() >0){
                    data = JSON.toJSONString(kList);
                    redisServer.set(key , data ,expireTime);
                }
            }
            resultVo.setCode( ReturnCode.SUCCESS);
            resultVo.setMessage("成功");
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData( kList );
            resultVo.setTotal( kList == null ? 0 : kList.size() );
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取日k-k线数据error", e);
        }
        return resultVo;
    }
    /**
     * 计算24h交易量，放定时器中
     * @param exchangeId
     * @param transactionName
     * @return
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public BigDecimal CountCoinAmount(Integer exchangeId,String transactionName) throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {
        List<String> list=new ArrayList<>(  );
        int d=0;
        Long nowTImeres = DateUtils.getCurrentDataLong();
        while (true) {
            LocalDateTime timeres2 = DateUtils.getDateTimeOfTimestamp( nowTImeres-d );
            String lastRowKey = DateUtils.localDateTimeFormatString(timeres2,DateUtils.format_ymdhm);//当前时间转成分钟
            String rowKey = exchangeId+"@"+transactionName+"@"+lastRowKey;

            String API_SERVICE_TRADES  = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.API_SERVICE_K_ACTION_TABLE_NAME
                    , HbaseTableUtils.API_SERVICE_K_ACTION_TABLE_NAME_FAMILY
                    , HbaseTableUtils.API_SERVICE_K_ACTION_QUALIFIER
                    , rowKey
            );
            if(API_SERVICE_TRADES != null){
                list.add( API_SERVICE_TRADES );
            }
            if ( d > 86400000) {
                break;
            }
            d = d + 60000;
        }

        BigDecimal allAmount=new BigDecimal( 0 );
        BigDecimal allAmountTem=new BigDecimal( 0 );
        TradesToKLine tradesToKLine;
        for(int i=0;i<list.size();i++){
            String object=list.get( i );
            if (object!=null){
                Object listArray = new JSONTokener(object).nextValue();
                if(listArray instanceof  net.sf.json.JSONArray){//老数据兼容问题
                    JSONArray jsonArray = JSON.parseArray(object);
                    allAmountTem = new BigDecimal(jsonArray.getString(5));
                    allAmount=allAmount.add(allAmountTem);
                }else{
                    TradesToKLine five= JSON.parseObject( object, TradesToKLine.class );
                    if(five!=null && five.getVolume()!=null){
                        allAmount=allAmount.add( new BigDecimal( five.getVolume() ));
                    }
                }
            }
        }
        return  allAmount;
    }

    public ApiResultVo<List<ApiMaxTradesVo>> historyTradesMax(Integer number, Integer exchangeId, String symbol) {
        ApiResultVo<List<ApiMaxTradesVo>> resultVo = new ApiResultVo<>();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        List<ApiMaxTradesVo> vo = new LinkedList<>();
        resultVo.setData(vo);
        if(null == number || null == exchangeId || StringUtils.isBlank(symbol)){//PARAMS_ERROR
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误");
            return resultVo;
        }
        try {
            List<PurchaseOrder> pList = purchaseOrderMapper.selectByEchangeAndSymbol(exchangeId,symbol,number);
            //获取汇率
            String rmbUsd = redisServer.get(RedisKeysUtils.RMB_USD_RATE);
            if(StringUtils.isBlank(rmbUsd)){
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("没有汇率");
                return resultVo;
            }
            BigDecimal rmbCny = new BigDecimal(rmbUsd);
            //计算返回实体
            ApiMaxTradesVo maxTradesVo;
            if(pList != null && pList.size() > 0){
                for(PurchaseOrder po : pList){
                    BigDecimal price = new BigDecimal(po.getPrice());
                    BigDecimal amount = new BigDecimal(po.getCount());
                    maxTradesVo = new ApiMaxTradesVo();
                    maxTradesVo.setTimestamp(po.getTimeStamp());
                    maxTradesVo.setAmount(amount.setScale(2, BigDecimal.ROUND_DOWN).toString());
                    maxTradesVo.setAmountPrice(amount.multiply(price).multiply(rmbCny).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    maxTradesVo.setPrice( getConverCut(price.multiply(rmbCny)));
                    maxTradesVo.setDeal_sign(po.getDealSign());
                    vo.add(maxTradesVo);
                }
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("无数据");
            }
        }catch (Exception e){
            LogTrace.error("k线-成交大单监控",e);
            e.printStackTrace();
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统错误");
        }
        return  resultVo;
    }

    public ApiResultVo<ApiCapitalInflowSituationDataVo> capitalInflowSituation(Integer exchangeId, String symbol, String timePartType) {
        Long st = System.currentTimeMillis();
        ApiResultVo<ApiCapitalInflowSituationDataVo> resultVo = new ApiResultVo<>();
        ApiCapitalInflowSituationDataVo dataVo = new ApiCapitalInflowSituationDataVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        List<ApiCapitalInflowSituationVo> vo = new LinkedList<>();
        dataVo.setCapitalInflowSituation(vo);
        resultVo.setData(dataVo);
        //判断参数是否正常
        if(null == exchangeId || StringUtils.isBlank(symbol) || StringUtils.isBlank(timePartType)){//PARAMS_ERROR
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误");
            return resultVo;
        }
        //判断参数是否正常
        if(!"3h".equals(timePartType) && !"1d".equals(timePartType)){//PARAMS_ERROR
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误-timePartType未传3h或1d");
            return resultVo;
        }
        //图标数据
        ChartVo chartVo = new ChartVo();
        List<String> x = new ArrayList<>();
        List<String> y = new ArrayList<>();
        try {
            //1d 3h
            String data = "";
            if("3h".equals(timePartType)){
                String redisKey3hData= RedisKeysUtils.API_SERVICE_TRADES_3H_DATA+"@"+exchangeId+"@"+symbol;
                data = redisServer.get(redisKey3hData);
            }else if("1d".equals(timePartType)){
                String redisKey1dData= RedisKeysUtils.API_SERVICE_TRADES_1D_DATA+"@"+exchangeId+"@"+symbol;
                data = redisServer.get(redisKey1dData);
            }
            if(StringUtils.isNotBlank(data)){
                JSONObject jsonObjectChart = JSON.parseObject(data);
                x = JSON.parseArray(JSON.toJSONString(jsonObjectChart.get("x")),String.class);
                y = JSON.parseArray(JSON.toJSONString(jsonObjectChart.get("y")),String.class);
            }
            String redisKey24HCapitalFlow= RedisKeysUtils.API_SERVICE_TRADES_24H_CAPITAL_FLOW_DATA+"@"+exchangeId+"@"+symbol;
            String redisData = redisServer.get(redisKey24HCapitalFlow);
            Map<String,ApiCapitalInflowSituationVo> allMap = new HashMap<>();
            JSONObject jsonObject = new JSONObject();
            if(StringUtils.isNotBlank(redisData)){
                jsonObject =  JSON.parseObject(redisData);
            }
            ApiCapitalInflowSituationVo today = new ApiCapitalInflowSituationVo();
            ApiCapitalInflowSituationVo fiveMinutes = new ApiCapitalInflowSituationVo();
            ApiCapitalInflowSituationVo tenMinutes = new ApiCapitalInflowSituationVo();
            ApiCapitalInflowSituationVo oneHours = new ApiCapitalInflowSituationVo();
            ApiCapitalInflowSituationVo dayHours = new ApiCapitalInflowSituationVo();
            if(null != jsonObject){
                today = JSON.parseObject(JSON.toJSONString(jsonObject.get("today")),ApiCapitalInflowSituationVo.class);
                fiveMinutes = JSON.parseObject(JSON.toJSONString(jsonObject.get("fiveMinutes")),ApiCapitalInflowSituationVo.class);
                tenMinutes = JSON.parseObject(JSON.toJSONString(jsonObject.get("tenMinutes")),ApiCapitalInflowSituationVo.class);
                oneHours = JSON.parseObject(JSON.toJSONString(jsonObject.get("oneHours")),ApiCapitalInflowSituationVo.class);
                dayHours = JSON.parseObject(JSON.toJSONString(jsonObject.get("dayHours")),ApiCapitalInflowSituationVo.class);
            }
            chartVo.setX(x);
            chartVo.setY(y);
            dataVo.setChartVo(chartVo);
            vo.add(today);
            vo.add(fiveMinutes);
            vo.add(tenMinutes);
            vo.add(oneHours);
            vo.add(dayHours);
            if(today != null && today.getBuySellAmount() != null){
                dataVo.setTodayCapitalInflow(today.getBuySellAmount());
            }
            resultVo.setCode(ReturnCode.SUCCESS);
            resultVo.setMessage("成功");
            LogTrace.info("k线-5、10、1h资金流入","耗时",String.valueOf(System.currentTimeMillis()-st));
        }catch (Exception e){
            LogTrace.error("k线-5、10、1h资金流入",e);
            e.printStackTrace();
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统错误");
        }
        return resultVo;
    }

    public ApiResultVo validateSymbolSelfSelect(Integer middleId, String userToken) {
        Long st = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo<>();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        if(middleId == null){
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误");
            return resultVo;
        }
        LogTrace.infoKvs("k线行情-查询交易对是否自选","userToken",userToken,"middleId",middleId.toString());
        try {
            Map<String,Object> stringObjectMap = new  HashMap();
            if(!StringUtils.isBlank(userToken)){
                Integer selfSelectFlag = valicatSymbolSelfSelect(userToken,middleId,1);
                stringObjectMap.put("selfSelectFlag",selfSelectFlag);
            }else{
                stringObjectMap.put("selfSelectFlag",2);
            }
            resultVo.setData(stringObjectMap);
            resultVo.setCode(ReturnCode.SUCCESS);
            resultVo.setMessage("成功");
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("k线行情-查询交易对是否自选",e);
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统错误");
        }
        LogTrace.info("k线行情-k线行情-查询交易对是否自选","总耗时",String.valueOf(System.currentTimeMillis()- st));
        return resultVo;
    }
    /**
     * 根据用户token判断此交易对和货币是否已自选
     * @param userToken 用户token
     * @param uniqueAnnotation 中间表id
     * @param type 1：交易对自选 2：货币自选
     * @return 2：未自选 1：已自选
     */
    public Integer valicatSymbolSelfSelect(String userToken,Integer uniqueAnnotation,Integer type){
        Integer selfSelectFlag = 2;
        BtUser btUser = commonService.getUserByToken(userToken);
        Integer user_id = null;
        if(btUser != null){
            user_id =  btUser.getId();
            if(user_id != null){
                List<Integer> middleList = new ArrayList<>();
                middleList.add(uniqueAnnotation);
                if(middleList.size() > 0){
                    Map<String,Object> params = new HashMap<>();
                    params.put("type",type);
                    params.put("uniqueAnnotationList",middleList);
                    params.put("user_id",user_id);
                    List<SelfSelected> selfList = selfSelectedMapper.getSelfSelectByMideleId(params);
                    if(selfList != null && selfList.size()>0){
                        return 1;
                    }
                }
            }
        }
        return selfSelectFlag;
    }

    /**
     * 5日资金净流入柱状图
     * @param middleId
     * @return
     */
    public ApiResultVo<AppFundsFlowVo> capitalInflowSituationOfFiveDay(Integer middleId) {
        Long st = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo<>();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        if(middleId == null){
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误");
            return resultVo;
        }
        List<AppFundsFlowVo> voData = new ArrayList<>();
        LogTrace.infoKvs("5日资金净流入柱状图","middleId",middleId.toString());
        try {
            List<String> searchDateList = new ArrayList<>();
            //计算今天以前5天日期
            LocalDateTime time = LocalDateTime.now();
            for(int i=5;i>0;i--){
                String searchDate = DateUtils.localDateTimeFormatString(time.minusDays(i),DateUtils.format_ymd);
                searchDateList.add(searchDate);
            }
            //查询5天日期数据
            Map<String,Object> params = new HashMap<>();
            params.put("middleId",middleId);
            params.put("funds_date",searchDateList);
            List<FundsFlow> fundsFlowList = fundsFlowMapper.selectEntityListByDate(params);
            //组装成list数据，按照日期升序
            if(fundsFlowList.size() > 0){
                Map<String,FundsFlow> mapData = new HashMap<>();
                for(FundsFlow fundsFlow : fundsFlowList){
                    mapData.put(fundsFlow.getFundsDate(),fundsFlow);
                }
                for(String str : searchDateList){
                    AppFundsFlowVo appFundsFlowVo = new AppFundsFlowVo();
                    if(mapData.containsKey(str)){
                        FundsFlow fundsFlow = mapData.get(str);
                        appFundsFlowVo.setFundsDate(str.substring(5,str.length()));
                        appFundsFlowVo.setFundsOnlyflow(fundsFlow.getFundsOnlyflow());
                    }else{
                        appFundsFlowVo.setFundsDate(str.substring(5,str.length()));
                        appFundsFlowVo.setFundsOnlyflow(null);
                    }
                    voData.add(appFundsFlowVo);
                }
            }
            if(voData.size() > 0){
                resultVo.setData(voData);
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("无数据");
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("5日资金净流入柱状图error",e);
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统错误");
        }
        LogTrace.info("5日资金净流入柱状图","总耗时",String.valueOf(System.currentTimeMillis()- st));
        return resultVo;
    }
    /**
     * k线数据-深度
     */
    public OrderResultVo MakeDepth(int exchangeId, String transactionName) {
        try {
            //redis
            String Rediskey = RedisKeysUtils.API_SERVICE_ORDER_BOOK + "@" + exchangeId + "@" + transactionName;
            String API_SERVICE_ORDER_BOOK = redisServer.get( Rediskey );
            String depthKey = RedisKeyApp.DEPTH_CACHE+exchangeId+":"+transactionName;
            OrderResultVo resultVo=new OrderResultVo();
            List<OrderBookVo> asksList=new ArrayList<>(  );
            List<OrderBookVo> bidsList=new ArrayList<>(  );
            List<OrderBookVo> asksWList=new ArrayList<>(  );
            List<OrderBookVo> bidsWList=new ArrayList<>(  );
            OrderBook orderBookOld;
            boolean isCache = false;
            if (API_SERVICE_ORDER_BOOK != null) {
                orderBookOld = JSON.parseObject(API_SERVICE_ORDER_BOOK,OrderBook.class);
                List<List<Object>> asks = orderBookOld.getData().getAsks();//卖单
                List<List<Object>> bids = orderBookOld.getData().getBids();//买单
                //买升序
                Collections.sort(bids, new Comparator<List<Object>>() {
                    @Override
                    public int compare(List<Object> o1, List<Object> o2) {
                        BigDecimal a1 = new BigDecimal(String.valueOf(o1.get(0)));
                        BigDecimal a2 = new BigDecimal(String.valueOf(o2.get(0)));
                        if(a2.compareTo(a1) > 0){
                            return 1;
                        }else if(a2.compareTo(a1) == 0){
                            return 0;
                        }else{
                            return -1;
                        }
                    }
                });
                //卖降序
                Collections.sort(asks, new Comparator<List<Object>>() {
                    @Override
                    public int compare(List<Object> o1, List<Object> o2) {
                        BigDecimal b1 = new BigDecimal(String.valueOf(o1.get(0)));
                        BigDecimal b2 = new BigDecimal(String.valueOf(o2.get(0)));
                        if(b1.compareTo(b2) > 0){
                            return 1;
                        }else if(b1.compareTo(b2) == 0){
                            return 0;
                        }else{
                            return -1;
                        }
                    }
                });
               //卖单升序20条
                for(int i=0;i<asks.size();i++){
                    if(i >19){
                        break;
                    }
                    List<Object> t = asks.get(i);
                    OrderBookVo orderBookVo = new OrderBookVo();
                    orderBookVo.setCount(getConverCut2(new BigDecimal(String.valueOf(t.get(1)))));
                    orderBookVo.setPrice(getConverCut2(new BigDecimal(String.valueOf(t.get(0)))));
                    asksWList.add(orderBookVo);
                }
                //买单升序20条
                for(int i=0;i<bids.size();i++){
                    if(i >19){
                        break;
                    }
                    List<Object> t = bids.get(i);
                    OrderBookVo orderBookVo = new OrderBookVo();
                    orderBookVo.setCount(getConverCut2(new BigDecimal(String.valueOf(t.get(1)))));
                    orderBookVo.setPrice(getConverCut2(new BigDecimal(String.valueOf(t.get(0)))));
                    bidsWList.add(orderBookVo);
                }
                resultVo.setAsksWeiList(asksWList);
                resultVo.setBidsWeiList(bidsWList);
                ListSortUtil sortUtil=new ListSortUtil();
                //卖单最小价格
                BigDecimal minPriceAsks=null;
               BigDecimal maxPriceAsks=null;
                BigDecimal lastOpenPrice = null;
                if(asks != null && asks.size() > 0){
                    for(int i =0;i<asks.size();i++){
                        JSONArray asksOb = JSON.parseArray( asks.get(i).toString());
                        BigDecimal asksPr = asksOb.getBigDecimal( 0 );
                        if(maxPriceAsks == null){
                            maxPriceAsks = asksPr;
                        }else{
                            if(asksPr.compareTo(maxPriceAsks) > 0){
                                maxPriceAsks = asksPr;
                            }
                        }
                        if(minPriceAsks == null){
                            minPriceAsks = asksPr;
                        }else{
                            if(asksPr.compareTo(minPriceAsks) < 0){
                                minPriceAsks = asksPr;
                            }
                        }
                    }
                }
                //买最大价格
               BigDecimal minPriceBids=null;
                BigDecimal maxPriceBids=null;
                if(bids != null && bids.size() > 0){
                    for(int i =0;i<bids.size();i++){
                        JSONArray bidsObj = JSON.parseArray( bids.get(i).toString());
                        BigDecimal bidsPr = bidsObj.getBigDecimal( 0 );
                        if(maxPriceBids == null){
                            maxPriceBids = bidsPr;
                        }else{
                            if(bidsPr.compareTo(maxPriceBids) > 0){
                                maxPriceBids = bidsPr;
                            }
                        }
                        if(minPriceBids == null){
                            minPriceBids = bidsPr;
                        }else{
                            if(bidsPr.compareTo(minPriceBids) < 0){
                                minPriceBids = bidsPr;
                            }
                        }
                    }
                }
               // BigDecimal minPrice=null;
               // BigDecimal maxPrice= null;
                //中间价格是取买单和卖单的最小和最大值的中间值，如果中间值小于买单最小值或者大于卖单最大值，取缓存
                //修改为买最大价格，卖最小价格，求平均
                if(maxPriceBids != null &&  minPriceAsks !=null){
                    lastOpenPrice = maxPriceBids.add(minPriceAsks).divide(BigDecimal.valueOf(2),10, BigDecimal.ROUND_DOWN);
                   // lastOpenPrice = minPrice.add(maxPrice.subtract(minPrice).divide(BigDecimal.valueOf(2),10,BigDecimal.ROUND_HALF_DOWN));
                    if(lastOpenPrice.compareTo(BigDecimal.ZERO) > 0){
                        //刻度计算,百分之10范围，分出20个
                        BigDecimal aksMaxBei= lastOpenPrice.add(lastOpenPrice.multiply(BigDecimal.valueOf(0.1)));
                        BigDecimal bidsMinBei= lastOpenPrice.subtract(lastOpenPrice.multiply(BigDecimal.valueOf(0.1)));
                        double interval =0;
                        double interval2 =0;
                        if(aksMaxBei.compareTo(maxPriceAsks)<0){ //卖单计算刻度
                            interval2 = lastOpenPrice.multiply(BigDecimal.valueOf(0.1)).abs().divide(BigDecimal.valueOf(20),10,BigDecimal.ROUND_DOWN).doubleValue();
                        }else{
                            interval2 = maxPriceAsks.subtract(lastOpenPrice).abs().divide(BigDecimal.valueOf(20),10,BigDecimal.ROUND_DOWN).doubleValue();
                        }
                        if(bidsMinBei.compareTo(minPriceBids)>0){
                            interval = lastOpenPrice.multiply(BigDecimal.valueOf(0.1)).abs().divide(BigDecimal.valueOf(20),10,BigDecimal.ROUND_DOWN).doubleValue();
                        }else{
                            interval = lastOpenPrice.subtract(minPriceBids).abs().divide(BigDecimal.valueOf(20),10,BigDecimal.ROUND_DOWN).doubleValue();
                        }

                        for(int j=1;j<=20;j++){
                            BigDecimal asksCount=BigDecimal.ZERO;
                            OrderBookVo asksvo=new OrderBookVo();
                            BigDecimal askPrice = lastOpenPrice.subtract(BigDecimal.valueOf(interval).multiply(BigDecimal.valueOf(j)));
                            for(int i=0;i<bids.size();i++){//买单
                                JSONArray asksObject = JSON.parseArray( bids.get( i ).toString() );
                                BigDecimal asksPrice = asksObject.getBigDecimal( 0 );
                                if(asksPrice.compareTo(askPrice)>=0 && asksPrice.compareTo(lastOpenPrice) <=0){
                                    asksCount = asksCount.add(new BigDecimal(String.valueOf(asksObject.get( 1))));
                                }
                            }
                            asksvo.setPrice(askPrice.stripTrailingZeros().toPlainString());
                            if (asksCount == null){
                                asksvo.setCount("0.00" );
                            }else{
                                asksvo.setCount(getConverCut(asksCount));
                            }
                            //askVom = askVom.add(new BigDecimal(asksvo.getCount()));
                            asksList.add( asksvo );

                            BigDecimal bidsCount=BigDecimal.ZERO;
                            OrderBookVo bidsvo=new OrderBookVo();
                            BigDecimal tmp = lastOpenPrice.add(BigDecimal.valueOf(interval2).multiply(BigDecimal.valueOf(j)));
                            for(int i =0;i<asks.size();i++){
                                JSONArray bidsObject = JSON.parseArray( asks.get( i ).toString() );
                                BigDecimal bidsPrice = bidsObject.getBigDecimal( 0 );
                                if(bidsPrice.compareTo(lastOpenPrice) >=0 && bidsPrice.compareTo(tmp) <=0){
                                    bidsCount = bidsCount.add(new BigDecimal(String.valueOf(bidsObject.get( 1))));
                                }
                            }
                            bidsvo.setPrice(tmp.stripTrailingZeros().toPlainString());
                            if (asksCount == null){
                                bidsvo.setCount( "0.00" );
                            }else{
                                bidsvo.setCount(getConverCut(bidsCount));
                            }
                           // bidsVom = bidsVom.add(new BigDecimal(bidsvo.getCount()));
                            bidsList.add( bidsvo );
                        }
                        sortUtil.mySort( bidsList,"price","asc" );//卖价格从小到大，数量从小到大
                        sortUtil.mySort( asksList,"price","asc" );//买价格从小到大，数量从大到小
                        resultVo.setAsksList( bidsList );//卖
                        resultVo.setBidsList( asksList );//买
                        resultVo.setLastPrice(lastOpenPrice.stripTrailingZeros().toPlainString());
                        //计算买单卖单数量，并且求出百分比
                        BigDecimal askVom = BigDecimal.ZERO;
                        BigDecimal bidsVom = BigDecimal.ZERO;
                        for(int i=0;i<bids.size();i++){//买单
                            JSONArray asksObject = JSON.parseArray( bids.get( i ).toString() );
                            bidsVom = bidsVom.add(new BigDecimal(String.valueOf(asksObject.get( 1))));

                        }
                        for(int i=0;i<asks.size();i++){//买单
                            JSONArray asksObject = JSON.parseArray( asks.get( i ).toString() );
                            askVom = askVom.add(new BigDecimal(String.valueOf(asksObject.get( 1))));

                        }
                        BigDecimal allvom = askVom.add(bidsVom);
                        if(allvom.compareTo(BigDecimal.valueOf(0)) != 0){
                            String asksPercent = askVom.divide(allvom,4,BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_DOWN).toString();
                            resultVo.setAsksPercent(asksPercent);
                            String bidsPercent = bidsVom.divide(allvom,4,BigDecimal.ROUND_HALF_DOWN).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_DOWN).toString();
                            resultVo.setBidsPercent(bidsPercent);
                        }else{
                            resultVo.setAsksPercent("0.00");
                            resultVo.setBidsPercent("0.00");
                        }
                        //买卖单放入缓存中，以及价格
                        redisServer.set(depthKey,resultVo!=null?JSON.toJSONString(resultVo):"");
                        return resultVo;
                    }else{
                        isCache = true;//取缓存
                    }
                }else{
                    isCache = true;//取缓存
                }
            }else{
                isCache = true;//取缓存
            }
            if(isCache){//取缓存数据
                String strJson = redisServer.get(depthKey);
                if(StringUtils.isNotBlank(strJson)){
                    resultVo = JSON.parseObject(strJson,OrderResultVo.class);
                    return resultVo;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("k线数据-深度",e);
        }
        return null;
    }

    /**
     * 获取深度数据
     * @param exchangeId
     * @param transactionName
     * @return
     */
    public ApiResultVo getDepth(Integer exchangeId, String transactionName) {
        Long st = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo<>();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        if(exchangeId == null || StringUtils.isBlank(transactionName)){
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误");
            return resultVo;
        }
        LogTrace.infoKvs("获取深度数据","middleId",exchangeId.toString(),"transactionName",transactionName);
        try {
            OrderResultVo vo = MakeDepth(exchangeId,transactionName);
            if(vo != null){
                resultVo.setData(vo);
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("无数据");
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取深度数据error",e);
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统错误");
        }
        LogTrace.info("获取深度数据","总耗时",String.valueOf(System.currentTimeMillis()- st));
        return resultVo;
    }
    public Map<String,List<AppOrderBookVo>> makeOrderBookLast(Integer exchangeId, String transactionName){
        try {
            LogTrace.infoKvs("获取委单15条数据Error","exchangeId",String.valueOf(exchangeId),"transactionName",transactionName);
            //redis
            String Rediskey = RedisKeysUtils.API_SERVICE_ORDER_BOOK + "@" + exchangeId + "@" + transactionName;
            String redisData = redisServer.get( Rediskey );
            //最新成交价
            /*Long nowTImeres = DateUtils.getCurrentDataLong();
            LocalDateTime timeres = DateUtils.getDateTimeOfTimestamp( nowTImeres );
            String redisPriceDate = DateUtils.localDateTimeFormatString(timeres,DateUtils.format_ymds);
            String Rediskey2 = RedisKeysUtils.API_SERVICE_K_ACTION_CHANGE_PRICE + "@" + exchangeId + "@" + transactionName+"@"+redisPriceDate;
            String redisData = redisServer.get( Rediskey2 );*/
            Map<String,List<AppOrderBookVo>> voMap = new HashMap<>();
            if(redisData!=null) {
                OrderBook orderBookOld;
                if(StringUtils.isNotBlank(redisData)){
                    orderBookOld = JSON.parseObject(redisData,OrderBook.class);
                    if(orderBookOld.getData() != null){
                        List<AppOrderBookVo> tmpList;
                        AppOrderBookVo vo ;
                        //获取买单15条
                        if(orderBookOld.getData().getAsks() != null && orderBookOld.getData().getAsks().size() > 0){
                            tmpList = new ArrayList<>();
                            int size = orderBookOld.getData().getAsks().size()>15?15:orderBookOld.getData().getAsks().size();
                            for(int i=1;i<=size;i++){
                                vo = new AppOrderBookVo();
                                List<Object> tmp = orderBookOld.getData().getAsks().get(size-i);
                                vo.setSort(i);
                                vo.setPrice(getConverCut(new BigDecimal(String.valueOf(tmp.get(0)))));
                                vo.setCount(getConverCut(new BigDecimal(String.valueOf(tmp.get(1)))));
                                tmpList.add(vo);
                            }
                            voMap.put("asks",tmpList);
                        }
                        //获取卖单15条
                        if(orderBookOld.getData().getBids() != null && orderBookOld.getData().getBids().size() > 0){
                            tmpList = new ArrayList<>();
                            int size = orderBookOld.getData().getBids().size()>15?15:orderBookOld.getData().getBids().size();
                            for(int i=1;i<=size;i++){
                                vo = new AppOrderBookVo();
                                List<Object> tmp = orderBookOld.getData().getBids().get(size-i);
                                vo.setSort(i);
                                vo.setPrice(getConverCut(new BigDecimal(String.valueOf(tmp.get(0)))));
                                vo.setCount(getConverCut(new BigDecimal(String.valueOf(tmp.get(1)))));
                                tmpList.add(vo);
                            }
                            voMap.put("bids",tmpList);
                        }
                    }
                }
            }
            List<AppOrderBookVo> resultList = new ArrayList<>();
            if(!voMap.containsKey("asks")){
                voMap.put("asks",resultList);
            }
            if(!voMap.containsKey("bids")){
                voMap.put("bids",resultList);
            }
            return voMap;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("获取委单15条数据Error",e);
        }
        return null;
    }
    /**
     * 保存5位有效数据如果小于1
     * @param lastPriceB
     * @return
     */
    public static String getConverCut(BigDecimal lastPriceB) {
        //String result = "0";
        BigDecimal result = BigDecimal.ZERO;
        result = lastPriceB!=null?lastPriceB.setScale(10,BigDecimal.ROUND_DOWN):result;
        if(result.compareTo(BigDecimal.valueOf(1)) >=0){
            result = result.setScale(2,BigDecimal.ROUND_DOWN);
        }else{
            BigDecimal divisor = BigDecimal.ONE;
            MathContext mc = new MathContext(5);
            result = result.divide(divisor, mc);
        }
        return result.stripTrailingZeros().toPlainString();
    }
    /**
     * 保存5位有效数据如果小于1
     * @param lastPriceB
     * @return
     */
    public static String getConverCut2(BigDecimal lastPriceB) {
        //String result = "0";
        BigDecimal result = BigDecimal.ZERO;
        result = lastPriceB!=null?lastPriceB.setScale(10,BigDecimal.ROUND_DOWN):result;
        if(result.compareTo(BigDecimal.valueOf(1)) >=0){
            result = result.setScale(2,BigDecimal.ROUND_DOWN);
        }else{
            BigDecimal divisor = BigDecimal.ONE;
            MathContext mc = new MathContext(5);
            result = result.divide(divisor, mc);
        }
        System.out.println(result);
        if(result.compareTo(BigDecimal.valueOf(1)) >=0){
            return result.toPlainString();
        }else{
            return result.stripTrailingZeros().toPlainString();
        }

    }
    public AppSelfSelectCoinPairVo getCurrencyData(Integer id) {
        AppSelfSelectCoinPairVo temResult = new AppSelfSelectCoinPairVo();;
        List<CurrencyInfo> CurrencyInfoList = redisCacheComponent.getCurrencyList();
        Map<Integer,CurrencyInfo> currencyInfoMap = new HashMap<>();
        CurrencyInfo currencytemp;
        for(CurrencyInfo currencyInfo : CurrencyInfoList) {
            currencyInfoMap.put(currencyInfo.getId(),currencyInfo);
        }
        currencytemp = currencyInfoMap.get(id);
        if(currencytemp!=null && StringUtils.isNotBlank(currencytemp.getCmcId())){

            ExchangeTransactionpairMiddle exchangeTransactionpairMiddle = new ExchangeTransactionpairMiddle();
            exchangeTransactionpairMiddle.setCurrencyId( id );
            List<ExchangeTransactionpairMiddle>  ExchangeTransactionpairMiddleList=exchangeTransactionpairMiddleMapper.selectByEntityList( exchangeTransactionpairMiddle );
            if(ExchangeTransactionpairMiddleList.size()>0){
                String priceRedisKey = RedisKeyApp.COIN_PRICE+currencytemp.getCmcId();
                String priceRedisData = redisServer.get(priceRedisKey);
                if(StringUtils.isNotBlank(priceRedisData)){
                    CoinPriceVo coinPriceVo = JSON.parseObject(priceRedisData,CoinPriceVo.class);
                    if(coinPriceVo!=null){
                        temResult.setType(2);
                        temResult.setAmount24h(coinPriceVo.getAmount24H());
                        temResult.setChange24h(coinPriceVo.getChang24h());
                        temResult.setChangeFlag(coinPriceVo.getChang());
                        temResult.setCoinOrPairName(currencytemp.getSymbol());
                        temResult.setPriceCny(coinPriceVo.getPriceCny());
                        temResult.setPriceUsd(coinPriceVo.getPriceUsd());
                        temResult.setCompareValue24H(coinPriceVo.getPriceCny24H());
                        temResult.setMiddleId(currencytemp.getId());
                        temResult.setCoinNameCn(currencytemp.getCoinNameCn());
                    }
                }
            }else {
                String redisCacheKey =  RedisKeysUtils.CURRENCY_MARKET+currencytemp.getCmcId();
                String result=redisServer.get( redisCacheKey);
                if (result!=null){
                    CurrencyQuotationResultVo currencyQuotationResultVo = JSON.parseObject( result,CurrencyQuotationResultVo.class );
                    temResult.setType( 2 );
                    temResult.setPriceCny( String.valueOf( currencyQuotationResultVo.getPriceCny()) );
                    temResult.setPriceUsd( currencyQuotationResultVo.getLastOpenPrice() );
                    temResult.setCoinNameCn( currencyQuotationResultVo.getCoinNameCn() );
                    temResult.setMiddleId( currencytemp.getId() );
                    temResult.setChange24h( String.valueOf( currencyQuotationResultVo.getChange24h() ) );
                    if(currencyQuotationResultVo.getChangFlag()==1){
                        temResult.setChangeFlag( "+" );
                    }else if(currencyQuotationResultVo.getChangFlag()==0){
                        temResult.setChangeFlag( "0" );
                    }else{
                        temResult.setChangeFlag( "-" );
                    }
                }
            }

        }
        return  temResult;
    }
    public List<AppSelfSelectCoinPairVo> getCurrencyData(String message) {
        List<AppSelfSelectCoinPairVo> result = new ArrayList<>();
        if(StringUtils.isNotBlank(message)){
            List<Integer> idList = JSON.parseArray(message,Integer.class);
            if(idList != null && idList.size() >0){
                for(Integer id : idList){
                    AppSelfSelectCoinPairVo temResult = getCurrencyData(id);
                    if(temResult != null){
                        result.add(temResult);
                    }
                }
            }
        }
        return  result;
    }
    public AppSelfSelectCoinPairVo getPairData(Integer exchangeId, String transactionName) {
        AppSelfSelectCoinPairVo temResult = new AppSelfSelectCoinPairVo();;
        String data = redisServer.get(RedisKeysUtils.K_ACTION_SELF_SELECT+"@"+exchangeId+"@"+transactionName);
        if(StringUtils.isNotBlank(data)){
            ApiKActionQuantizationVo k = JSON.parseObject(data,ApiKActionQuantizationVo.class);
            if(k != null){
                temResult = new AppSelfSelectCoinPairVo();
                temResult.setType(1);
                temResult.setAmount24h(getConverCut(new BigDecimal(k.getAmount())));
                temResult.setChange24h(k.getChangePrice().toString());
                temResult.setChangeFlag(k.getChangFlag().toString());
                temResult.setCoinOrPairName(k.getTransactionName());
                temResult.setExchangeId(exchangeId);
                temResult.setExchangeName(k.getExchangeName());
                //temResult.setPairId(middle.getTransactionId());
                temResult.setPriceCny(getConverCut(new BigDecimal(k.getLastOpenPrice())));
                temResult.setPriceUsd(getConverCut(new BigDecimal(k.getLastOpenPriceUsd())));
                //temResult.setMiddleId(middle.getId());
            }
        }
        return  temResult;
    }

    public ApiResultVo<List<TradesToKLine>> kActionByPart(String exchangeId, String transactionName, String type) {
        ApiResultVo resultVo = new ApiResultVo();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        try {
            if(null == exchangeId || StringUtils.isBlank(transactionName)||StringUtils.isBlank(type)){//PARAMS_ERROR
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("参数错误");
                return resultVo;
            }
            LogTrace.infoKvs("k线数据-K线图-多维度","exchangeId",exchangeId,"transactionName",transactionName,"type",type);
            String rowKeyHead="";
            DateTimeFormatter formatTime = DateUtils.format_ymdhm;
            int min = 0;
            LocalDateTime timeres = LocalDateTime.now().plusMinutes(min);
            if("5M".equals(type)){
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_5M;
                min =5;
                int yu = timeres.getMinute()%5;
                timeres = timeres.minusMinutes(yu);
            }else if("15M".equals(type)){
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_15M;
                min =15;
                int yu = timeres.getMinute()%15;
                timeres = timeres.minusMinutes(yu);
            }else if("30M".equals(type)){
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_30M;
                min =30;
                int yu = timeres.getMinute()%30;
                timeres = timeres.minusMinutes(yu);
            }else if("1H".equals(type)){
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_1H;
                formatTime =DateUtils.format_ymdh;
                min =1;
                int yu = timeres.getMinute()%60;
                timeres = timeres.minusMinutes(yu);
            }else if("4H".equals(type)){
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_4H;
                formatTime =DateUtils.format_ymdh;
                min =4;
                while (timeres.getHour()%4 != 0){//得到准确分钟
                    timeres = timeres.minusHours(1);
                }
            }else if("1D".equals(type)){//日k
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_1D;
                formatTime = DateUtils.format_ymds;
            }else if("1W".equals(type)){//周k
                formatTime = DateUtils.format_ymds;
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_1W;
                while (timeres.getDayOfWeek() != DayOfWeek.SUNDAY){
                    timeres = timeres.minusDays(1);
                }
            }else if("1MON".equals(type)){//月k
                rowKeyHead = HbaseTableUtils.K_ACTION_K_LINE_ROW_KEY_1Mo;
                formatTime = DateUtils.format_ymds;
                int yu = timeres.getDayOfMonth() - 1;
                timeres = timeres.minusDays(yu);
            }else{
                resultVo.setCode(ReturnCode.PARAMS_ERROR);
                resultVo.setMessage("type参数错误");
                return resultVo;
            }
            List<TradesToKLine> resultList=new ArrayList<>();
            int size = 1;
            for(int i=0;i<500;i++){
                if(size > 300){
                    break;
                }
                try {
                    String rowKey = rowKeyHead+"@"+exchangeId + "@" + transactionName + "@" + DateUtils.localDateTimeFormatString(timeres, formatTime);
                    TradesToKLine tradesToKLine = getHbaseDataByRowKey(rowKey);
                    if (tradesToKLine != null && StringUtils.isNotBlank(tradesToKLine.getVolume())){
                        //处理所有失去精度问题
                        if(StringUtils.isNotBlank(tradesToKLine.getOpenPrice())){
                            tradesToKLine.setOpenPrice(getConverCut(tradesToKLine.getOpenPrice()));
                        }
                        if(StringUtils.isNotBlank(tradesToKLine.getHighestPrice())){
                            tradesToKLine.setHighestPrice(getConverCut(tradesToKLine.getHighestPrice()));
                        }
                        if(StringUtils.isNotBlank(tradesToKLine.getLowestPrice())){
                            tradesToKLine.setLowestPrice(getConverCut(tradesToKLine.getLowestPrice()));
                        }
                        if(StringUtils.isNotBlank(tradesToKLine.getClosePrice())){
                            tradesToKLine.setClosePrice(getConverCut(tradesToKLine.getClosePrice()));
                        }
                        if(StringUtils.isNotBlank(tradesToKLine.getVolume())){
                            tradesToKLine.setVolume(getConverCut(tradesToKLine.getVolume()));
                        }
                        resultList.add(tradesToKLine);
                        size++;
                    }
                    if("5M".equals(type) || "15M".equals(type) || "30M".equals(type)){
                        timeres = timeres.minusMinutes(min);
                    }else if( "1H".equals(type) || "4H".equals(type)){//时k
                        timeres = timeres.minusHours(min);
                    }else if("1D".equals(type)){//日k
                        timeres = timeres.minusDays(1);
                    }else if("1W".equals(type)){//周k
                        timeres = timeres.minusDays(7);
                    }else if("1MON".equals(type)){//月k
                        timeres = timeres.minusMonths(1);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    LogTrace.error("k线数据-K线图-单个数据Error",e);
                }
            }
            //判断数据是否存在
            if(resultList.size() > 0){
                Collections.reverse( resultList );
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("未查询到数据");
            }
            resultVo.setData( resultList );
            resultVo.setPages( resultList.size() );
        }catch (Exception e){
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统异常");
            LogTrace.error("k线数据-K线图-两天数据Error",e);
            e.printStackTrace();
        }
        return resultVo;
    }

    /**
     * k线失去精度
     * @param lastPriceB
     * @return
     */
    public static String getConverCut(String lastPriceB) {
        BigDecimal result = BigDecimal.ZERO;
        result = StringUtils.isNotBlank(lastPriceB)?new BigDecimal(lastPriceB).setScale(12,BigDecimal.ROUND_DOWN):BigDecimal.ZERO;
        /*if(result.compareTo(BigDecimal.valueOf(1)) >=0){
            result = result.setScale(2,BigDecimal.ROUND_DOWN);
        }else{
            BigDecimal divisor = BigDecimal.ONE;
            MathContext mc = new MathContext(5);
            result = result.divide(divisor, mc);
        }*/
        return result.stripTrailingZeros().toPlainString();
    }
    /**
     * 根据rowkey查询k线不同维度数据（非一分钟）
     * @param rowKey
     * @return
     * @throws Exception
     */
    public TradesToKLine getHbaseDataByRowKey(String rowKey) throws Exception{
        Map<String, Object> hbaseData = hbaseBaseQueryComponent.selectData(HbaseTableUtils.CURRENCY_INFO_K_LINE_TABLE_NAME
                , rowKey);
        if(null != hbaseData && hbaseData.get("volume") != null && hbaseData.get("openPrice") != null && hbaseData.get("highestPrice") != null&& hbaseData.get("lowestPrice") != null&& hbaseData.get("closePrice") != null){
            TradesToKLine tradesToKLine = new TradesToKLine();
            tradesToKLine.setTimestamp(hbaseData.get("timestamp").toString());
            tradesToKLine.setVolume(hbaseData.get("volume").toString());
            tradesToKLine.setOpenPrice(hbaseData.get("openPrice").toString());
            tradesToKLine.setClosePrice(hbaseData.get("closePrice").toString());
            tradesToKLine.setHighestPrice(hbaseData.get("highestPrice").toString());
            tradesToKLine.setLowestPrice(hbaseData.get("lowestPrice").toString());
            return tradesToKLine;
        }
        return null;
    }

    public ApiResultVo getCurrencyInfo(Integer middleId) {
        Long st = System.currentTimeMillis();
        ApiResultVo resultVo = new ApiResultVo<>();
        resultVo.setDataStamp(System.currentTimeMillis());
        resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        if(middleId == null ){
            resultVo.setCode(ReturnCode.PARAMS_ERROR);
            resultVo.setMessage("参数错误");
            return resultVo;
        }
        LogTrace.infoKvs("交易行情获取货币信息","middleId",middleId.toString());
        try {
            ExchangeTransactionpairMiddle middle = new ExchangeTransactionpairMiddle();
            middle.setId(middleId);
            middle = exchangeTransactionpairMiddleMapper.selectByEntity(middle);
            if(middle != null && middle.getCurrencyId() != null){
                CurrencyInfo currencyInfo = new CurrencyInfo();
                currencyInfo.setId(middle.getCurrencyId());
                currencyInfo = currencyInfoMapper.selectByEntityOwn(currencyInfo);
                resultVo.setData(currencyInfo);
                resultVo.setCode(ReturnCode.SUCCESS);
                resultVo.setMessage("成功");
            }else{
                resultVo.setCode(ReturnCode.DATA_NOT_EXIST);
                resultVo.setMessage("无数据");
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("交易行情获取货币信息error",e);
            resultVo.setCode(ReturnCode.ERROR);
            resultVo.setMessage("系统错误");
        }
        LogTrace.info("交易行情获取货币信息","总耗时",String.valueOf(System.currentTimeMillis()- st));
        return resultVo;
    }

    public List<AppSelfSelectCoinPairVo> getPairDataList(String message) {
        List<AppSelfSelectCoinPairVo> resultList = new ArrayList<>();
        if(StringUtils.isNotBlank(message)){
            List<WsExchangePairVo> voList = JSON.parseArray(message,WsExchangePairVo.class);
            if(voList != null && voList.size() > 0){
                for(WsExchangePairVo exchangePairVo : voList){
                    AppSelfSelectCoinPairVo data = this.getPairData(exchangePairVo.getExchangeId(),exchangePairVo.getPair());
                    if(data != null){
                        resultList.add(data);
                    }
                }
            }
        }
        return resultList;
    }
}
